<?php if ($sf_user->hasFlash('test_flash')){
?>		
			<div id="notification" class="nNote nSuccess hideit" onclick="$('#notification').hide('slow')" style="margin-top: 40px;">
                <p><strong>SUCCESS: </strong>Template Content Saved</p>
         </div>

<?php 
}?>

<form action="template_content/create" method="post" id="template_content_form">


<?php $body_content = " "; ?>

<input type="hidden" value="<?php echo $template->getId() ?>" name="template_id">
<div class="widget" id="template_content_div">
	<div class="head"><h5 class="iList">Template Content Definition for: <?php echo $template->getName() ?></h5> <div style="float:right;margin-right:10px; margin-top:5px;"><input type="button" id="go_back" value="<- Go back" class="greyishBtn submitForm" onclick="window.location.href='<?php echo  url_for("templates/index")?>'" ></div> </div>
	<?php foreach ($content_types as $content_type) {
		if ($content_type->getId() != sfConfig::get("app_content_type_footer")){
		?>
		
		<div id="content_for_type_<?php echo $content_type->getId()?>" class="template_content">
			<div id="content_type_<?php echo $content_type->getId()?>">
				<?php echo $content_type->getName()?>
			</div>
			
			
			<?php if (count($all_levels) > 0 ) {?>
			<div id="buttons_<?php echo $content_type->getId()?>" style="clear:both">
				<div style="float:left; margin-right: 20px; margin-top: 4px;">
					<select id="sl_<?php echo $content_type->getId()?>">
						<?php 
						foreach ($all_levels as $level){
						?>
						<option value="<?php echo $level->getId()?>">
							<?php echo $level->getName()?>
						</option>
						<?php if ($content_type->getId() == sfConfig::get('app_content_type_body')){?>
						<option value="<?php echo $level->getId()?>_d">
							<?php echo $level->getName() . '.description'?>
						</option>						
						
						<?php 						
						}
						}
						?>
					</select>
				</div> 
				<div style="float:left">
				<?php if ($content_type->getId() == sfConfig::get('app_content_type_body') ){ ?>
				<a style="cursor: pointer;"  onclick="addLevelW('<?php echo $content_type->getId()?>')" title="" class="btnIconLeft mr10" id="add_category_button_<?php echo $content_type->getId()?>"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add category Level</span></a>
				
				<?php if ($template->getShowComments() == 1){?>
					<a style="cursor: pointer;"  onclick="addCommentTag('<?php echo $content_type->getId()?>')" title="" class="btnIconLeft mr10" id="add_comment_button_<?php echo $content_type->getId()?>"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add comment tag</span></a>
				<?php }?>
				<?php }
				else{
				?>
				<a  style="cursor: pointer;"  onclick="addLevel('<?php echo $content_type->getId()?>')" title="" class="btnIconLeft mr10" id="add_category_button_<?php echo $content_type->getId()?>"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add category Level</span></a>
				<?php 
				}
				
				?>
        		
        		</div>
        		
				<?php if ($content_type->getId() == sfConfig::get('app_content_type_body') ){ ?>      
				

				<?php if (count($listings) > 0){?>
				<div style="float:left; margin-right: 20px; margin-top: 4px;">
					<select id="sl_listing">
						<?php 
						foreach ($listings as $listing){
						?>
						
						<option value="<?php echo $listing->getId()?>">
							<?php echo $listing->getName()?>
						</option>
											
						
						<?php 						
						}
						?>
					</select>
				</div>
				<div style="float:left">
					<a style="cursor: pointer;"  onclick="addListing('<?php echo $content_type->getId()?>')" title="" class="btnIconLeft mr10" id="add_category_button_<?php echo $content_type->getId()?>"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add listing</span></a>
        		</div>	        		
        		
        		<?php }
        		
				}
				
				?>
        		


        		
        		
			</div>
			
			<?php }?>
			<div style="clear: both; margin-bottom: 10px"></div>
                   
                	<?php if ($content_type->getId() == sfConfig::get('app_content_type_body') ){
                		//echo  $template_content_arr[$content_type->getId()];
						$body_content = $template_content_arr[$content_type->getId()] != null ? $template_content_arr[$content_type->getId()]->getTheContent() : "";
                	?>
                	<div class="widget" style="margin-top:10px"> 
                    <div class="head"><h5 class="iPencil">WYSIWYG editor</h5></div>
                    
					<div>
						<textarea id="elm1" rows="35" style="width:700px;"  mce_editable="true" name="ta_<?php echo $content_type->getId()?>">
							<?php echo $body_content ?>
						</textarea>
					</div>                    
                    
                    
              <!--       <textarea class="wysiwyg" rows="5" cols="" id="ta_<?php echo $content_type->getId()?>" name="ta_<?php echo $content_type->getId()?>"><?php echo $body_content ?></textarea> --> 
                    	
                          
                    </div>     
                    
<?php if ($content_type->getId() == sfConfig::get("app_content_type_body")){			?>
			
				<div style="clear: both; background-color: rgb(243, 243, 243); padding: 5px; margin-bottom:10px;">
						<div style="clear: both; margin-bottom: 30px;">
						<?php $checked =  $template->getIncludeApiCode() == 1 ? 'checked="checked"' : '' ?>
							<div style="float:left"><input type="checkbox" name="include_api_code" id="include_api_code" value="1" <?php echo $checked?>/></div>
							<div  style="float: left; margin-top: 4px; margin-left: 10px;">Include Places API Data?</div>
						</div>
							
							<div id="api_content" style="margin-top: 10px;">
							
								<div  style="clear: both; margin-left: 20px;" >
									<div style="float:left; margin-right: 10px; ">Search string </div>
									<div style="float:left; margin-right: 10px;"> <input type="text" name="tx_search_variables" id="tx_search_variables" style="height: 24px; width: 320px;" value="<?php echo $template->getSearchStr()?>" /> </div>
									<div style="margin-right: 10px; float: left;">
										<select id="sl_search_variables">
											
											<?php 
											foreach ($all_levels as $level){
												?>
												<option value="<?php echo $level->getId()?>">
													<?php echo $level->getName()?>
												</option>
											<?php }?>
										</select>
									</div>
									<div style="float:left">
										<a  style="cursor: pointer;"  onclick="addLevelAlias('search_variables')" title="" class="btnIconLeft mr10" id="add_category_button_footer_alias"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add category Level</span></a>
									</div>								
								</div>
								
								
								<div style="clear:both; margin-left: 20px;">
									<div style="float:left">Type</div>
									<div style="float:left; margin-left: 58px ">
										<select name="search_type" id="search_type">
											<option value="">--Place type--</option>
											<option value="accounting">accounting</option>
											<option value="airport">airport</option>
											<option value="amusement_park">amusement_park</option>
											<option value="aquarium">aquarium</option>
											<option value="art_gallery">art_gallery</option>
											<option value="atm">atm</option>
											<option value="bakery">bakery</option>
											<option value="bank">bank</option>
											<option value="bar">bar</option>
											<option value="beauty_salon">beauty_salon</option>
											<option value="bicycle_store">bicycle_store</option>
											<option value="book_store">book_store</option>
											<option value="bowling_alley">bowling_alley</option>
											<option value="bus_station">bus_station</option>
											<option value="cafe">cafe</option>
											<option value="campground">campground</option>
											<option value="car_dealer">car_dealer</option>
											<option value="car_rental">car_rental</option>
											<option value="car_repair">car_repair</option>
											<option value="car_wash">car_wash</option>
											<option value="casino">casino</option>
											<option value="cemetery">cemetery</option>
											<option value="church">church</option>
											<option value="city_hall">city_hall</option>
											<option value="clothing_store">clothing_store</option>
											<option value="convenience_store">convenience_store</option>
											<option value="courthouse">courthouse</option>
											<option value="dentist">dentist</option>
											<option value="department_store">department_store</option>
											<option value="doctor">doctor</option>
											<option value="electrician">electrician</option>
											<option value="electronics_store">electronics_store</option>
											<option value="embassy">embassy</option>
											<option value="establishment">establishment</option>
											<option value="finance">finance</option>
											<option value="fire_station">fire_station</option>
											<option value="florist">florist</option>
											<option value="food">food</option>
											<option value="funeral_home">funeral_home</option>
											<option value="furniture_store">furniture_store</option>
											<option value="gas_station">gas_station</option>
											<option value="general_contractor">general_contractor</option>
											<option value="grocery_or_supermarket">grocery_or_supermarket</option>
											<option value="gym">gym</option>
											<option value="hair_care">hair_care</option>
											<option value="hardware_store">hardware_store</option>
											<option value="health">health</option>
											<option value="hindu_temple">hindu_temple</option>
											<option value="home_goods_store">home_goods_store</option>
											<option value="hospital">hospital</option>
											<option value="insurance_agency">insurance_agency</option>
											<option value="jewelry_store">jewelry_store</option>
											<option value="laundry">laundry</option>
											<option value="lawyer">lawyer</option>
											<option value="library">library</option>
											<option value="liquor_store">liquor_store</option>
											<option value="local_government_office">local_government_office</option>
											<option value="locksmith">locksmith</option>
											<option value="lodging">lodging</option>
											<option value="meal_delivery">meal_delivery</option>
											<option value="meal_takeaway">meal_takeaway</option>
											<option value="mosque">mosque</option>
											<option value="movie_rental">movie_rental</option>
											<option value="movie_theater">movie_theater</option>
											<option value="moving_company">moving_company</option>
											<option value="museum">museum</option>
											<option value="night_club">night_club</option>
											<option value="painter">painter</option>
											<option value="park">park</option>
											<option value="parking">parking</option>
											<option value="pet_store">pet_store</option>
											<option value="pharmacy">pharmacy</option>
											<option value="physiotherapist">physiotherapist</option>
											<option value="place_of_worship">place_of_worship</option>
											<option value="plumber">plumber</option>
											<option value="police">police</option>
											<option value="post_office">post_office</option>
											<option value="real_estate_agency">real_estate_agency</option>
											<option value="restaurant">restaurant</option>
											<option value="roofing_contractor">roofing_contractor</option>
											<option value="rv_park">rv_park</option>
											<option value="school">school</option>
											<option value="shoe_store">shoe_store</option>
											<option value="shopping_mall">shopping_mall</option>
											<option value="spa">spa</option>
											<option value="stadium">stadium</option>
											<option value="storage">storage</option>
											<option value="store">store</option>
											<option value="subway_station">subway_station</option>
											<option value="synagogue">synagogue</option>
											<option value="taxi_stand">taxi_stand</option>
											<option value="train_station">train_station</option>
											<option value="travel_agency">travel_agency</option>
											<option value="university">university</option>
											<option value="veterinary_care">veterinary_care</option>
											<option value="zoo">zoo</option>
										</select>			
									
									</div>	
									<div style="float:left; margin-left: 20px">Results count: <input type="text" value="<?php echo $template->getSearchResultsCount() ?>" name="search_results_count" style="width: 30px; height: 25px; text-align: center;">  </div>		
								</div>
								
						 		<div style="clear: both; margin-left: 20px; margin-top: 35px;">
						 			<a  style="cursor: pointer;"  onclick="addVariableW('places_api_content')" title="" class="btnIconLeft mr10" id="add_category_button_footer_alias"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add Places API variable to body</span></a>
						 			<div style="display: inline; color: red; position: relative; bottom: 11px;" id="custom_error1"></div>
						 		</div>
					 		
					 		</div>
					<div style="clear:both;"></div>
					
				</div>	
						
				<div style="clear: both; background-color: rgb(243, 243, 243); padding: 5px; margin-bottom:10px; margin-top: 10px">
						<div style="clear: both; margin-bottom: 30px;">
						<?php $checked =  $template->getIncludeWeatherApi() == 1 ? 'checked="checked"' : '' ?>
							<div style="float:left"><input type="checkbox" name="include_weather_api" id="include_weather_api" value="1" <?php echo $checked?>/></div>
							<div  style="float: left; margin-top: 4px; margin-left: 10px;">Include Weather API Data?</div>
						</div>
							
							<div id="api_content" style="margin-top: 10px;">
							
								<div  style="clear: both; margin-left: 20px;" >
									<div style="float:left; margin-right: 10px; ">Weather target city </div>
									<div style="float:left; margin-right: 10px;"> <input type="text" name="weather_target" id="tx_weather_target" style="height: 24px; width: 320px;" value="<?php echo $template->getWeatherTarget()?>" /> </div>
									
									<div style="margin-right: 10px; float: left;">
										<select id="sl_weather_target">
											
											<?php 
											foreach ($all_levels as $level){
												?>
												<option value="<?php echo $level->getId()?>">
													<?php echo $level->getName()?>
												</option>
											<?php }?>
										</select>
									</div>
									<div style="float:left">
										<a  style="cursor: pointer;"  onclick="addLevelAlias('weather_target')" title="" class="btnIconLeft mr10" id="add_category_button_footer_alias"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add category Level</span></a>
									</div>
									
									<div style="clear: both; color: rgb(138, 138, 138); position: relative; left: 110px; top: -6px;">Format: <b>City State Country</b></div>								
								</div>
								
								
								
								
						 		<div style="clear: both; margin-left: 20px;">
						 			<a  style="cursor: pointer;"  onclick="addVariableW1('weather_api')" title="" class="btnIconLeft mr10" id="add_category_button_footer_alias"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add Weather API variable to body</span></a>
						 			<div style="display: inline; color: red; position: relative; bottom: 11px;" id="custom_error2"></div>
						 		</div>
					 		
					 		</div>
					<div style="clear:both;"></div>
					
				</div>			
				
				<div style="clear: both; background-color: rgb(243, 243, 243); padding: 5px; margin-bottom:10px; margin-top: 10px">
						<div style="clear: both; margin-bottom: 30px;">
						<?php $checked =  $template->getIncludeMapsApi() == 1 ? 'checked="checked"' : '' ?>
							<div style="float:left"><input type="checkbox" name="include_maps_api" id="include_maps_api" value="1" <?php echo $checked?>/></div>
							<div  style="float: left; margin-top: 4px; margin-left: 10px;">Include Travel Distance, Time and Price?</div>
						</div>	
						 		<div style="clear: both; margin-left: 20px;">
						 			<a  style="cursor: pointer;"  onclick="addVariableW2('maps_api')" title="" class="btnIconLeft mr10" id="add_category_button_footer_alias"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add Travel Distance, Time and Price to body</span></a>
						 			<div style="display: inline; color: red; position: relative; bottom: 11px;" id="custom_error2"></div>
						 		</div>									
				</div>				
				
			
			<?php }?>                    
                    
                        
                    <?php } 
                    else if ($content_type->getId() != sfConfig::get('app_content_type_body')){
                    ?>
                    <textarea mce_editable="false" rows="3" cols="120" id="ta_<?php echo $content_type->getId()?>" name="ta_<?php echo $content_type->getId()?>" style="font-size:14px;line-height: 22px;padding:5px;"><?php echo $template_content_arr[$content_type->getId()] != null ? $template_content_arr[$content_type->getId()]->getTheContent() : "" ?></textarea>
                    	
                    
                    <?php 
                    }
                    ?>
                
                			
			<hr style="color:#ccc;margin-bottom: 10px;margin-top: 10px;"></hr>
			<div id="content_level_combination_<?php echo $content_type->getId()?>">
			
			</div>
		
		
		</div>
		
		<?php
		} 
	} ?>
	
<div id="content_for_type_footer" class="template_content">
<div style="clear:both; margin-right: 20px; margin-top: 5px;">Alias when footer</div>
	<div style="clear:both">
		<div style="float:left; margin-right: 20px; margin-top: 4px;">
			<select id="sl_footer_alias">
				<?php 
				foreach ($all_levels as $level){
				?>
				<option value="<?php echo $level->getId()?>">
					<?php echo $level->getName()?>
				</option>
				<?php if ($content_type->getId() == sfConfig::get('app_content_type_body')){?>
				<option value="<?php echo $level->getId()?>_d">
					<?php echo $level->getName() . '.description'?>
				</option>						
				
				<?php 						
				}
				}
				?>
			</select>
		</div>
		<div style="float:left">
			<a  style="cursor: pointer;"  onclick="addLevelAlias('footer_alias')" title="" class="btnIconLeft mr10" id="add_category_button_footer_alias"><img src="<?php echo image_path('icons/dark/add.png')?>" alt="" class="icon" /><span>Add category Level</span></a>
		</div>	
	</div>
			<div id="buttons_footer" style="clear:both;margin-top:10px;">
				
				<div style="float:left; margin-right: 20px; margin-bottom: 20px; margin-top: 5px;">
					<input type="text" name="tx_footer_alias" id="tx_footer_alias" style="height: 24px; width: 765px;" value="<?php echo $template->getAliasWhenFooter()?>" />
				</div>
			</div>
	   <div style="clear:both"></div>
<hr style="color:#ccc;margin-bottom: 10px"></hr>	              
</div>	


	
<div id="content_for_type_footer" class="template_content">
			<div id="content_type_footer">
				Footer
			</div>
			<div id="buttons_footer" style="clear:both;margin-top:10px;">
				<div style="float:left; margin-right: 20px; margin-bottom: 20px;">Available templates</div>
				<div style="float:left; margin-right: 20px; margin-bottom: 20px;">
					<select id="sl_template_footer" name="sl_template_footer">
						<option value="">
							--Select template--
						</option>					
						<?php 
						foreach ($footer_templates  as $footer_template){
							$selected = $footer_template->getId() == $template->getFooterId() ? 'selected' : '';
						?>
						<option value="<?php echo $footer_template->getId()?>" <?php echo $selected?>>
							<?php echo $footer_template->getName()?>
						</option>
						
						<?php 						
						}
						?>
					</select>
				</div>

			</div>
                   
</div>	





	
	<div style="clear: both; margin-bottom: 10px"></div>
</div>
	<div style="float:right; margin-top:20px;">
		<input type="submit" id="ajax_test" value="Save" class="greyishBtn submitForm" >
	</div>
	<div style="float:right; margin-top:20px;">
		<?php if($deletable == true){?>
			<!-- <input type="button" id="delete" value="Delete" class="redBtn submitForm"> -->
		<?php }?>
	</div>	
</form>

<script>

/*
$("#include_api_code").click(function (event){
	if ($(this).is(":checked")){
		$("#api_content").show();
	}    
	else{
		$("#api_content").hide();
		
	}
})*/

$("#search_type option[value='<?php echo $template->getSearchTypes()?>']").prop("selected", true);


function addLevel(content_type_id){


	var textarea_content = $("#ta_" + content_type_id).attr('value');
	
	var select_content = $("#sl_" + content_type_id + " option:selected").text();

	var str_identifier = "#%#";
	
	$("#ta_" + content_type_id).attr('value',textarea_content + str_identifier + $.trim(select_content) + str_identifier + " ");

	$("#ta_" + content_type_id).focus();
	

}

function addLevelAlias(content_type_id){

	var textarea_content = $("#tx_" + content_type_id).attr('value');
	
	var select_content = $("#sl_" + content_type_id + " option:selected").text();

	var str_identifier = "#%#";

	
	$("#tx_" + content_type_id).attr('value',textarea_content + str_identifier + $.trim(select_content) + str_identifier + " ");

	$("#tx_" + content_type_id).focus();
	

}

function addLevelW(content_type_id){
	
	var select_content = $("#sl_" + content_type_id + " option:selected").text();

	var str_identifier = "#%#";

	var text_to_insert = str_identifier + $.trim(select_content) + str_identifier + " ";

	tinyMCE.execCommand('mceInsertContent',false,text_to_insert);

	return false;

}

function addVariableW(value){

	if ($.trim($("#tx_search_variables").val()) != "" || $("#search_type").val() != "" ){
		
		var str_identifier = "#%%#";
	
		var text_to_insert = str_identifier + value + str_identifier + " ";
	
		tinyMCE.execCommand('mceInsertContent',false,text_to_insert);
		$("#custom_error1").html("");
	}
	else{
		$("#custom_error1").html("Please enter a Search String or select a Place Type");
	}
	return false;

}

function addVariableW1(value){

	if ($.trim($("#tx_weather_target").val()) != "" ){
		
		var str_identifier = "#%%#";
	
		var text_to_insert = str_identifier + value + str_identifier + " ";
	
		tinyMCE.execCommand('mceInsertContent',false,text_to_insert);
		$("#custom_error2").html("");
	}
	else{
		$("#custom_error2").html("Please enter the variable corresponding to the weather target city");
	}
	return false;

}

function addVariableW2(value){

		
		var str_identifier = "#%%#";
	
		var text_to_insert = str_identifier + value + str_identifier + " ";
	
		tinyMCE.execCommand('mceInsertContent',false,text_to_insert);

	return false;

}


function addCommentTag(content_type_id){

	var select_content = "comments";

	var str_identifier = "##%%##";

	var text_to_insert = str_identifier + $.trim(select_content) + str_identifier + " ";

	tinyMCE.execCommand('mceInsertContent',false,text_to_insert);

	return false;

}


$('form').jqTransform({imgPath:'../images/forms'});



$("#delete").click(function (event){
	
	jConfirm('Are you sure you want to delete the contents of this Template?', 'Confirmation Dialog', function(r){
		if (!r){
			return false;
		} 
		else{
			$('form').attr('action',"<?php echo url_for("template_content/delete?template_id=" . $template->getId())?>");
			$('form').submit();
		}
		});
	
}
)


function addListing(content_type_id){
	
	var select_content = $("#sl_listing" + " option:selected").text();

	var str_identifier = "%#%";
	
	var text_to_insert = str_identifier + $.trim(select_content) + str_identifier + " ";

	tinyMCE.execCommand('mceInsertContent',false,text_to_insert);

	return false;

}
</script>